home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / gnuplot / term / tgif.trm < prev    next >
Text File  |  1993-09-15  |  5KB  |  259 lines

  1. /*
  2.  * $Id: tgif.trm%v 3.50 1993/07/09 05:35:24 woo Exp $
  3.  */
  4.  
  5. /* N O T   F I N I S H E D ! ! ! ! ! ! ! */
  6.  
  7. /* GNUPLOT - tgif.trm */
  8. /*
  9.  * Copyright (C) 1990   
  10.  *
  11.  * Permission to use, copy, and distribute this software and its
  12.  * documentation for any purpose with or without fee is hereby granted, 
  13.  * provided that the above copyright notice appear in all copies and 
  14.  * that both that copyright notice and this permission notice appear 
  15.  * in supporting documentation.
  16.  *
  17.  * Permission to modify the software is granted, but not the right to
  18.  * distribute the modified code.  Modifications are to be distributed 
  19.  * as patches to released version.
  20.  *  
  21.  * This software  is provided "as is" without express or implied warranty.
  22.  * 
  23.  * This file is included by ../term.c.
  24.  *
  25.  * This terminal driver supports:
  26.  *     tgif
  27.  *
  28.  * AUTHORS
  29.  *  Neal Holtz
  30.  * 
  31.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  32.  * 
  33.  */
  34.  
  35.  
  36. /* tgif driver by Neal Holtz, holtz@civeng.carleton.ca */
  37.  
  38. #include "tgif.h"
  39.  
  40. #define TGIF_XMAX 750
  41. #define TGIF_YMAX 750
  42.  
  43. #define TGIF_XLAST (TGIF_XMAX - 1)
  44. #define TGIF_YLAST (TGIF_YMAX - 1)
  45.  
  46. #define TGIF_VTIC (TGIF_YMAX/80)
  47. #define TGIF_HTIC (TGIF_YMAX/80)
  48.  
  49. /* TGIF Courier size 5 = 15x24, size 4 = 11x19, size 3 = 9x16
  50.     ascender+descender = 19+5,           15+4,           13+3 */
  51.  
  52. #define TGIF_VCHAR1    19
  53. #define TGIF_HCHAR1    11
  54. #define TGIF_CHAR_ASC    15
  55. #define TGIF_CHAR_DESC     (TGIF_VCHAR1-TGIF_CHAR_ASC)
  56.  
  57. #define YTRANS(y) (TGIF_YMAX-(y))
  58.                          
  59. typedef struct {
  60.     int    x, y;
  61. } Tgif_point;
  62.  
  63. int    tgif_fileVersion = 10;
  64. int    tgif_just = JUST_L;
  65. int    tgif_ang = ROTATE0;
  66. int    tgif_font = FONT_HEL;
  67. int    tgif_style = STYLE_NR;    /* text style */
  68. int    tgif_size = 4;        /* text size */
  69. int    tgif_asc = TGIF_CHAR_ASC;        /* text ascender, descender */
  70. int    tgif_des = TGIF_CHAR_DESC;
  71.  
  72. int    tgif_linewidth = LINE_MEDIUM;
  73. int    tgif_dash = 0;
  74.  
  75. char    *tgif_colour = "yellow";
  76. int    tgif_objId = 100;
  77.  
  78. #define TGIF_VSINIT    100
  79. #define TGIF_VSINCR    100
  80. int    tgif_vsmax = 0;            /* max possible number of vertices */
  81. int    tgif_nv = 0;            /* current number of vertices */
  82. Tgif_point    *tgif_v = NULL;        /* coordinates of vertices of polyline */
  83.  
  84.  
  85.  
  86. TGIF_AddVertex( x, y )
  87. int    x, y;
  88. {
  89.     Tgif_point    *p;
  90.  
  91.     if( tgif_v == NULL ) {
  92.         tgif_v = (Tgif_point *)malloc( TGIF_VSINIT*sizeof(Tgif_point) );
  93.         tgif_nv = 0;
  94.         if( tgif_v == NULL ) {
  95.             fprintf( stderr, "Unable to malloc() space for vertices.\n" );
  96.             exit( 1 );
  97.         }
  98.         tgif_vsmax = TGIF_VSINIT;
  99.     }
  100.     if( tgif_nv >= tgif_vsmax ) {
  101.         tgif_v = (Tgif_point *)realloc( tgif_v, (tgif_vsmax+TGIF_VSINCR)*sizeof(Tgif_point) ); 
  102.         if( tgif_v == NULL ) {
  103.             fprintf( stderr, "Unable to realloc() space for vertices.\n" );
  104.             exit( 1 );
  105.         }
  106.         tgif_vsmax += TGIF_VSINCR;
  107.     }
  108.     p = tgif_v + tgif_nv++;
  109.     p->x = x;
  110.     p->y = YTRANS(y);
  111.     if( tgif_nv > 1 && p[-1].x == p[0].x && p[-1].y == p[0].y )
  112.         tgif_nv--;
  113. }
  114.  
  115.  
  116. TGIF_Flush( lstyle )
  117. int    lstyle;        /* line style */
  118. {
  119.     int    i;
  120.  
  121.     if( tgif_nv >= 2 ) {
  122.         fprintf( outfile, "poly('%s',%d,[%d,%d",
  123.             tgif_colour, tgif_nv, tgif_v[0].x, tgif_v[0].y );
  124.         for( i = 1; i < tgif_nv; i++ )
  125.             fprintf( outfile, ",%d,%d", tgif_v[i].x, tgif_v[i].y );
  126.         fprintf( outfile, "],%d,%d,%d,%d,%d,%d,%d,[\n]).\n",
  127.             lstyle, tgif_linewidth, 1,    /* style, width, pen */
  128.             tgif_objId++,
  129.             0, 0,        /* curved, fill */
  130.             tgif_dash );
  131.     }
  132.     tgif_nv = 0;
  133. }
  134.     
  135.     
  136.  
  137.  
  138. TGIF_init()
  139. {
  140.     tgif_just = JUST_L;
  141.     tgif_ang = ROTATE0;
  142.     tgif_font = FONT_HEL;
  143.     tgif_style = STYLE_NR;
  144.     tgif_linewidth = LINE_MEDIUM;
  145.     tgif_dash = 0;
  146.     tgif_nv = 0; 
  147. }
  148.  
  149.  
  150. TGIF_graphics()
  151. {
  152.     fprintf(outfile,"state(0,%d,0,0,0,16,1,0,2,1,0,0,1,0,1,0,1,0,3,0,0).\n", tgif_fileVersion);
  153.     fprintf(outfile,"%%\n");
  154.     fprintf(outfile,"%% @(#)$Header: /a/woo/src/gwork/term/RCS/tgif.trm%v 3.50 1993/07/09 05:35:24 woo Exp $\n");
  155.     fprintf(outfile,"%%\n");
  156.     tgif_nv = 0;
  157. }
  158.  
  159.  
  160. TGIF_text()
  161. {
  162.     TGIF_Flush(LS_PLAIN);
  163. }
  164.  
  165.  
  166. TGIF_reset()
  167. {
  168.     TGIF_Flush(LS_PLAIN);
  169. }
  170.  
  171.  
  172. TGIF_linetype(linetype)
  173. int linetype;
  174. {
  175.     TGIF_Flush(LS_PLAIN);
  176.     if( linetype == -2 )        /* use thinner lines for border and axis */
  177.         tgif_dash = 0, tgif_linewidth = LINE_THIN;
  178.     else if( linetype == -1 )
  179.         tgif_dash = 1, tgif_linewidth = LINE_THIN;
  180.     else
  181.         tgif_dash = linetype % MAXDASHES, tgif_linewidth = LINE_MEDIUM;
  182. }
  183.  
  184.  
  185. TGIF_move(x,y)
  186. unsigned int x,y;
  187. {
  188.     TGIF_Flush(LS_PLAIN);
  189.     TGIF_AddVertex( x, y );
  190. }
  191.  
  192.  
  193. TGIF_vector(x,y)
  194. unsigned int x,y;
  195. {
  196.     TGIF_AddVertex( x, y );
  197. }
  198.  
  199.  
  200. TGIF_put_text(x,y,str)
  201. unsigned int x, y;
  202. char *str;
  203. {
  204.     TGIF_Flush(LS_PLAIN);
  205.     fprintf( outfile, "text('%s',%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,[\n\t\"%s\"]).\n",
  206.         tgif_colour, 
  207.         x, YTRANS(y)-(TGIF_CHAR_DESC+(TGIF_CHAR_ASC/2)),
  208.         tgif_font, tgif_style, tgif_size,
  209.         1,    /* number of lines */
  210.         tgif_just, tgif_ang,
  211.         1,        /* pen */
  212.         TGIF_HCHAR1*strlen(str), TGIF_VCHAR1,
  213.         tgif_objId++,
  214.                 0,     /* dpi */
  215.         tgif_asc, tgif_des,
  216.         str );
  217. }
  218.  
  219. int TGIF_text_angle(ang)
  220. int ang;
  221. {
  222.     TGIF_Flush(LS_PLAIN);
  223.     if( ang == 1 )
  224.         tgif_ang = ROTATE270;
  225.     else
  226.         tgif_ang = ROTATE0;
  227.     return TRUE;
  228. }
  229.  
  230. int TGIF_justify_text(mode)
  231. enum JUSTIFY mode;
  232. {
  233.     TGIF_Flush(LS_PLAIN);
  234.     switch(mode) {
  235.     case LEFT:    
  236.         tgif_just = JUST_L;     
  237.         break;
  238.     case CENTRE:    
  239.         tgif_just = JUST_C;    
  240.         break;
  241.     case RIGHT:    
  242.         tgif_just = JUST_R;    
  243.         break;
  244.     default:    
  245.         tgif_just = JUST_L;    
  246.         break;
  247.     }
  248.     return TRUE;
  249. }
  250.  
  251. TGIF_arrow( sx, sy, ex, ey )
  252. int    sx, sy, ex, ey;
  253. {
  254.     TGIF_Flush(LS_PLAIN);
  255.     TGIF_AddVertex( sx, sy );
  256.     TGIF_AddVertex( ex, ey );
  257.     TGIF_Flush(LS_RIGHT);
  258. }
  259.